#include <iostream>

using namespace std;

int n, m;

int main (void) {
	while (true) {
		cin >> n >> m;
		if (n == 0) break;
		int s = 0; //if f(n) = 0; (n==1)
		for (int i=2; i<=n; i++) {
			s = (s+m)%i;
		}
		cout << s+1 << endl;
	}
}
